package jifenbao.com.jifenbao;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/23 0023.
 */
public class PointRecordList extends AppCompatActivity{
    private ListView mylistView;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_point_record);

        mylistView = (ListView)findViewById(R.id.point_record);

        List<Map<String,String>> recordlist = new ArrayList<>();
        Map<String,String> map1 = new HashMap<>();
        map1.put("record_name","扫码积分");
        map1.put("record_count","+"+10);
        map1.put("record_time","2016/3/25 19:00");
        recordlist.add(map1);

        Map<String,String> map2 = new HashMap<>();
        map2.put("record_name","支付得积分");
        map2.put("record_count","+"+50);
        map2.put("record_time","2016/3/25 19:00");
        recordlist.add(map2);

        Map<String,String> map3 = new HashMap<>();
        map3.put("record_name","扫码积分");
        map3.put("record_count","+"+10);
        map3.put("record_time","2016/3/25 19:00");
        recordlist.add(map3);

        Map<String,String> map4 = new HashMap<>();
        map4.put("record_name","积分兑换礼品");
        map4.put("record_count_2","-"+100);
        map4.put("record_time","2016/3/25 19:00");
        recordlist.add(map4);

        Map<String,String> map5 = new HashMap<>();
        map5.put("record_name","扫码积分");
        map5.put("record_count","+"+10);
        map5.put("record_time","2016/3/25 19:00");
        recordlist.add(map5);

        Map<String,String> map6 = new HashMap<>();
        map6.put("record_name","扫码积分");
        map6.put("record_count","+"+10);
        map6.put("record_time","2016/3/25 19:00");
        recordlist.add(map6);

        Map<String,String> map7 = new HashMap<>();
        map7.put("record_name","积分兑换礼品");
        map7.put("record_count_2","-"+300);
        map7.put("record_time","2016/3/25 19:00");
        recordlist.add(map7);

        Map<String,String> map8 = new HashMap<>();
        map8.put("record_name","扫码积分");
        map8.put("record_count","+"+10);
        map8.put("record_time","2016/3/25 19:00");
        recordlist.add(map8);

        Map<String,String> map9 = new HashMap<>();
        map9.put("record_name","扫码积分");
        map9.put("record_count","+"+60);
        map9.put("record_time","2016/3/25 19:00");
        recordlist.add(map9);

        SimpleAdapter myAdapter = new SimpleAdapter(this,recordlist,R.layout.activity_point_record_item,
                new String[]{"record_name","record_count","record_time","record_count_2"},
                new int[]{R.id.record_name,R.id.record_count,R.id.record_time,R.id.record_count_2});
        mylistView.setAdapter(myAdapter);

        shortClickListener();
        longClickListener();
    }

    public void shortClickListener(){
        mylistView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            public void onItemClick(AdapterView<?> parent,View view,int position,long id){
                Toast.makeText(PointRecordList.this,"你点击了第"+(position)+"个记录",Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void longClickListener(){
        mylistView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(PointRecordList.this,"你长按了第"+(position)+"个记录",Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    }
}
